﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Tools;
using Pixysoft.Framework.Sockets.Controller;

namespace Pixysoft.Framework.Sockets.Core
{
    class SessionProfile : ISessionProfile
    {
        bool isLogin = false;

        string identifier = null;
        string nickName = null;
        string loginName = null;
        string userCode = null;
        string token = null;

        DateTime createDate = DateTime.MinValue;
        DateTime registerDate = DateTime.MinValue;

        public SessionProfile(string identifier)
        {
            this.identifier = identifier;

            this.createDate = GlobalTimer.Instance.GetGlobalTime();
        }

        public void Login(string nickName, string loginName, string userCode, string token)
        {
            this.nickName = nickName;
            this.loginName = loginName;
            this.userCode = userCode;
            this.token = token;

            this.registerDate = GlobalTimer.Instance.GetGlobalTime();
            this.isLogin = true;

            // register session

            SessionPoolController.Instance.LoginSession(this.identifier, this.userCode);
        }

        public void Logout()
        {
            if (!this.IsLogin)
                return;

            SessionPoolController.Instance.LogoutSession(this.userCode);

            this.nickName = null;
            this.loginName = null;
            this.userCode = null;

            this.isLogin = false;
        }

        public string UserCode
        {
            get { return userCode; }
        }

        public DateTime CreateDate
        {
            get { return createDate; }
        }

        public string NickName
        {
            get { return nickName; }
        }

        public string LoginName
        {
            get { return loginName; }
        }

        public string Token
        {
            get { return token; }
        }

        public bool IsLogin
        {
            get { return isLogin; }
        }

        public void Dispose()
        {
            this.isLogin = false;

            this.userCode = null;

            // do nothing

        }

    }
}
